﻿using System;
using System.Web.Services;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.Globalization;

namespace VirtualEarth
{
    /// <summary>
    /// Summary description for VisualizeGraphML
    /// </summary>
    [WebService(Namespace = "http://pl.edu.wat.nosoiFigthers/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class VisualizeGraphML : System.Web.Services.WebService
    {
        [WebMethod]
        public string DisplayGraph(System.Xml.XmlReader reader)
        {
            //QuickGraph.Serialization.GraphMLDeserializer<Nullable, Nullable, Nullable> a = new QuickGraph.Serialization.GraphMLDeserializer<Nullable, Nullable, Nullable>();
            //a.Deserialize(
            return "Hello World";
        }

        [WebMethod]
        public static double[] GetGeoCode(string strAddress)
        {
            string strKey = "ABQIAAAAt21w088otvkx4dydGkSFzhTiWYdC4kK5HJo75hRqCbZEyPurWxRFE2iDTU5WiKeD_zuNhg5zVaDZbw";

            string sPath = "http://maps.google.com/maps/geo?q=" + strAddress + "&output=csv&key=" + strKey;


            WebClient client = new WebClient();

            string[] eResult = client.DownloadString(sPath).ToString().Split(',');
            
            string latitude = eResult.GetValue(2).ToString();
            string longitude = eResult.GetValue(3).ToString();

            return new double[] { Convert.ToDouble(latitude, NumberFormatInfo.InvariantInfo), Convert.ToDouble(longitude, NumberFormatInfo.InvariantInfo) };
        }
    }
}
